﻿@model IEnumerable<Von.Web.Structs.OptionInfo>
@{
    ViewData["Title"] = "系统选项管理";
}
<h2>系统选项<a class="btn btn-link" onclick="NewOption()">新建系统选项</a></h2>
<table id="OptionList" class="table">
    <thead>
        <tr>
            <th>参数名称</th>
            <th>参数类型</th>
            <th>参数说明</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>@Html.DisplayFor(modelItem => item.OptName)</td>
                @switch (item.OptKind) {
                    case 0:<td>列表</td> break;
                    case 1:<td>键值</td> break;
                    case 2:<td>配置</td> break;
                    case 3:<td>XML</td> break;
                    case 4:<td>JSON</td> break;
                }
                <td>@Html.DisplayFor(modelItem => item.OptInfo)</td>
                <td>
                    <input type="button" class="btn-link" onclick="EditOption(this, '@item.OptName')" value="编辑"> | 
                    <input type="button" class="btn-danger" onclick="DeleteOption(this, '@item.OptName')" value="删除">
                </td>
            </tr>
        }
    </tbody>
</table>
<!-- 模态框（Modal） -->
<div class="modal fade" id="OptionEditor" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true" data-mode="new">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header" style="background-color:aquamarine;">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="ModalLabel">系统选项编辑</h4>
            </div>
            <div class="modal-body">
                <div class="input-group">
                    <label for="OptName" class="input-group-addon column-prompt">参数名称</label>
                    <input id="OptName" class="form-control" />
                </div>
                <div class="input-group">
                    <label for="OptKind" class="input-group-addon column-prompt">参数类型</label>
                    <select id="OptKind" class="form-control">
                        <option value="0" selected>列表</option>
                        <option value="1">键值</option>
                        <option value="2">配置</option>
                        <option value="3">XML</option>
                        <option value="4">JSON</option>
                    </select>
                </div>
                <div class="input-group">
                    <label for="OptInfo" class="input-group-addon column-prompt">参数说明</label>
                    <input id="OptInfo" class="form-control" />
                </div>
                <div class="form-group">
                    <label for="OptValues" class="control-label">参数值</label>
                    <textarea id="OptValues" class="form-control" style="width:100%"></textarea>
                </div>
            </div>
            <div class="modal-footer">
                <input type="hidden" id="ID" />
                <div class="form-group">
                    <input value="保存" class="btn btn-default" onclick="SaveOption()" />
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</div>
<script type="text/javascript">

    function NewOption() {
        von.selectRow();
        von.editor.clear();
        von.editor.display("new");
    }
    function EditOption(btn, id) {
        von.selectRow(btn);
        AjaxPostData("@Url.Ajax("GetByOption")", { ID: id }, function (data) {
            von.editor.setData(data);
            von.editor.display("edit");
        });
    }
    function DeleteOption(btn, id) {
        if (confirm('确定删除吗？')) {
            von.selectRow(btn);
            AjaxPostData('@Url.Ajax("DeleteOption")', { 'ID': id }, function (result) { von.deleteRow(); });
        }
    }
    function CheckOption(){
        var msg = "";
        if($("#OptName").val() == "") msg += "参数名称必须录入，不允许为空。";
        return msg;
    }
    function SaveOption() {
        var msg = CheckOption();
        if (msg != "") return SysWarning(msg);
        var data = {};
        von.editor.getData(data);
        if (von.editor.mode == "new") AjaxPostData("@Url.Ajax("AddOption")", data, function (data) { von.appendRow(von.getHtml(data)); von.editor.close(); });
        else AjaxPostData("@Url.Ajax("EditOption")", data, function (data) { von.replaceRow(von.getHtml(data)); von.editor.close(); });
    }
</script>
@Html.Import(Von.Web.Html.EImportSection.BodyTrailler, "OptionInit",
    @<script>
        var von = new VonGrid({
            app: "Option",
            keyName: "OptName",
            displayFields: ["OptName","OptKind"],
            fields: ["OptName","OptKind","OptInfo","OptValues"],
            onAddFields: function (data) {
                von.addCell(data["OptName"]);
                switch (data["OptKind"]) {
                    case 0: von.addCell("列表"); break;
                    case 1: von.addCell("键值"); break;
                    case 2: von.addCell("配置"); break;
                    case 3: von.addCell("XML"); break;
                    case 4: von.addCell("JSON"); break;
                }
                von.addCell(data["OptInfo"]);
            }
        });
    </script>
)
